package com.zcc.makingfriend.controller;

import com.zcc.makingfriend.dao.Commented;
import com.zcc.makingfriend.service.CommentedService;
import com.zcc.makingfriend.untils.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author zcc
 */
@Api(tags = "回复评论管理")
@RestController
@RequestMapping("/commented")
public class CommentedController {

    @Autowired
    CommentedService commentedService;

    @ApiOperation("回复评论")
    @PostMapping("/add")
    public Result addCommented(@RequestBody Commented commented) {
        int i = commentedService.addCommented(commented);
        if (i == 1) {
            return Result.success("回复评论成功");
        }
        return Result.fail("回复评论失败");
    }

    @ApiOperation("举报回复评论")
    @GetMapping("/report/{id}")
    public Result reportCommented(@PathVariable Long id) {
        int i = commentedService.reportCommented(id);
        if (i == 1) {
            return Result.success("举报回复评论成功");
        }
        return Result.fail("举报回复评论失败");
    }

    @ApiOperation("删除回复评论")
    @DeleteMapping("/delete/{id}")
    public Result deleteCommented(@PathVariable Long id) {
        int i = commentedService.deleteCommented(id);
        if (i == 1) {
            return Result.success("删除回复评论成功");
        }
        return Result.fail("删除回复评论失败");
    }

    @ApiOperation("是否点赞回复评论")
    @GetMapping("/isLike/{id}/{isLike}/{likes}")
    public Result isLikeComment(@PathVariable Long id, @PathVariable int isLike, @PathVariable Long likes) {
        int likeComment = commentedService.isLikeCommented(id, isLike, likes);
        if (likeComment == 1) {
            return Result.success(isLike == 1? "点赞" : "取消点赞" + "成功");
        }
        return Result.success(isLike == 1? "点赞" : "取消点赞" + "失败");
    }

    @ApiOperation("找到回复评论")
    @GetMapping("/findByCommentId/{commentId}")
    public Result findCommentedByCommentId(@PathVariable Long commentId) {
        List<Commented> commentedByCommentId = commentedService.findCommentedByCommentId(commentId);
        return Result.success(commentedByCommentId);
    }



}
